package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.OperateLogMapper;
import com.itheima.pojo.OperateLog;
import com.itheima.pojo.PageResult;
import com.itheima.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private OperateLogMapper  OperatorLogMapper;
    /**
     * 记录日志
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public PageResult<OperateLog> storeLog(Integer page, Integer pageSize) {
        // 1设置分页参数
        PageHelper.startPage(page,pageSize);
        //  2调用Mapper层方法,返回日志集合
        List<OperateLog> list = OperatorLogMapper.selectLog();
        //3 解析集合并封装到PageResult对象中返回i
        Page<OperateLog> p = (Page<OperateLog>) list;
        return new PageResult<OperateLog>(p.getTotal(),p.getResult());
    }
}
